import { AES, mode, enc, pad } from 'crypto-js';


// 裁剪 key 的函数
function ensureKeyLength(key: string): string {
    if (key.length === 32) {
        return key;
    }
    if (key.length < 32) {
        return key.padEnd(32, '0');
    }
    return key.slice(0, 32); // 截取前 32 个字符
}

// AES 加密
function encrypt(text: string, secretKey: string): string {
    const key = enc.Utf8.parse(secretKey);
    const encrypted = AES.encrypt(text, key, {
        mode: mode.ECB,
        padding: pad.Pkcs7
    });
    return encrypted.toString();
}


export {
    ensureKeyLength,
    encrypt
}